#ifndef _PICKHANDLER_H_
#define _PICKHANDLER_H_

#include "SelectionManager.h"
#include <osg/Notify>
#include <osg/io_utils>
#include <osgGA/GUIEventHandler>
#include <osgUtil/IntersectionVisitor>
#include <osgUtil/PolytopeIntersector>
#include <osgUtil/LineSegmentIntersector>
#include <osgViewer/Viewer>
//#include <osgFX/Scribe>
#include <iostream>
#include <set>

class QItemSelectionModel;

class PickHandler : public osgGA::GUIEventHandler 
{
public: 
    PickHandler(SelectionManager* selectionManager):
        _mx(0.0),_my(0.0), _selectionManager(selectionManager) {}

    bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
	void setItemSelectionModel(QItemSelectionModel* selectionModel) { _selectionModel = selectionModel; }

protected:
    bool pick(const osgGA::GUIEventAdapter& ea, osgViewer::Viewer* viewer);
    //void toggleScribe(osg::Group* parent, osg::Node* node);
	osg::Node* findSelectableNode(const osg::NodePath& nodePath);
	bool isSelectable(osg::Node* pNode);

	float _mx,_my;
	SelectionManager* _selectionManager;
	QItemSelectionModel* _selectionModel;
};

#endif
